package com.getpebble.android.jskit;

import com.getpebble.android.common.core.trace.Trace;
import java.util.UUID;
import org.json.JSONObject;

public class JsInstalledApplicationInfo extends JsApplicationInfo {
    JSONObject mCachedFullAppinfoJson;
    private final String mInstalledAbsPathOnFilesys;
    private final boolean mIsBuiltInApp;
    private String mJsCodeDigest;
    private Long mScannedUpdateTime;
    private final SpecialApplicationTypeE type;

    public enum SpecialApplicationTypeE {
        __INVALID__,
        NativeAppWithZeroUuid,
        Normal
    }

    public boolean isNativeAppSpecialInfoObject() {
        return SpecialApplicationTypeE.NativeAppWithZeroUuid.equals(this.type);
    }

    public boolean isNormalJsAppObject() {
        return SpecialApplicationTypeE.Normal.equals(this.type);
    }

    public long setUpdatedScannedTime(long v) {
        long t;
        synchronized (this.mScannedUpdateTime) {
            t = this.mScannedUpdateTime.longValue();
            this.mScannedUpdateTime = Long.valueOf(v);
        }
        return t;
    }

    public void setJsCodeDigest(String digest) {
        if (digest == null) {
            digest = "";
        }
        this.mJsCodeDigest = digest;
    }

    public String[] digests() {
        return new String[]{super.appInfoDigest(), this.mJsCodeDigest};
    }

    public JsInstalledApplicationInfo() {
        this(SpecialApplicationTypeE.__INVALID__);
    }

    public JsInstalledApplicationInfo(SpecialApplicationTypeE typeE) {
        this.mScannedUpdateTime = new Long(0);
        this.mJsCodeDigest = "";
        this.mInstalledAbsPathOnFilesys = null;
        this.mIsBuiltInApp = false;
        this.mCachedFullAppinfoJson = null;
        this.type = typeE;
    }

    public static JsInstalledApplicationInfo makeNativeAppPlaceholderObject() {
        return new JsInstalledApplicationInfo(SpecialApplicationTypeE.NativeAppWithZeroUuid);
    }

    public JsInstalledApplicationInfo(String installedAbsPathOnFilesys, JsApplicationInfo base) {
        super(base);
        this.mScannedUpdateTime = new Long(0);
        this.mJsCodeDigest = "";
        this.mInstalledAbsPathOnFilesys = installedAbsPathOnFilesys;
        this.mIsBuiltInApp = false;
        this.mCachedFullAppinfoJson = null;
        this.type = SpecialApplicationTypeE.Normal;
    }

    public UUID getUuid() {
        try {
            if (this.mCachedFullAppinfoJson != null) {
                UUID uuid = UUID.fromString(this.mCachedFullAppinfoJson.getString("uuid"));
                if (uuid != null) {
                    return uuid;
                }
            }
        } catch (Throwable e) {
            Trace.error("JsInstalledApplicationInfo", e);
        }
        return super.getUuid();
    }

    public String getInstalledAbsPathOnFilesystem() {
        return this.mInstalledAbsPathOnFilesys == null ? "" : this.mInstalledAbsPathOnFilesys;
    }

    public String toString() {
        if (isNormalJsAppObject()) {
            String ss = super.toString();
            String s = "{" + (this.mInstalledAbsPathOnFilesys == null ? "(nopath)" : this.mInstalledAbsPathOnFilesys) + "}";
            if (ss != null) {
                return ss + "::(JsInstalledApplicationInfo)" + s;
            }
            return s;
        } else if (isNativeAppSpecialInfoObject()) {
            return "(special_native_app_id_object)";
        } else {
            return "(invalid object)";
        }
    }
}
